#include "StdAfx.h"
#include "DBackground.h"
#include "../Engine/DAnimation.h"

DBackground::DBackground(boost::shared_ptr<DAnimation> anim)
: m_anim(anim)
, m_scrollingVel(0, 0)
, m_bScrolling(false)
{
}

DBackground::~DBackground(void)
{
}

void DBackground::update(float dt)
{
    if(isScrolling())
    {
	    m_pos.x += m_scrollingVel.x*dt;
        m_pos.y += m_scrollingVel.y*dt;

	    if(m_pos.x < -(int)m_anim->width())
	    {
		    m_pos.x = 0;
	    }
    }
}

const vec2& DBackground::pos() const
{
	return m_pos;
}

boost::shared_ptr<DAnimation> DBackground::animation()
{
	return m_anim;
}

void DBackground::setScrollingVel(const vec2& vel)
{
    m_scrollingVel = vel;

    if(vel.x != 0 || vel.y != 0)
    {
        m_bScrolling = true;
    }
    else
    {
        m_bScrolling = false;
    }
}

bool DBackground::isScrolling() const
{
    return m_bScrolling;
}